# -*- coding: utf-8 -*-
from datetime import timedelta
from utils.operators.cluster_for_spark_sql_operator import SparkSqlOperator

from jms_hi.dim.dim_network_whole_massage import jms_dim__dim_network_whole_massage
from jms_hi.dwd.tab.dwd_tab_barscan_arrival_base_hi import jms_dwd__dwd_tab_barscan_arrival_base_hi
from jms_hi.dwd.tab.dwd_tab_barscan_send_base_hi import jms_dwd__dwd_tab_barscan_send_base_hi
from jms_hi.dwd.dwd_wide_tms_road_waybill_hf import jms_dwd__dwd_wide_tms_road_waybill_hf
from jms_hi.dwd.tab.dwd_tab_reback_transfer_express_base_hi import jms_dwd__dwd_tab_reback_transfer_express_base_hi
from jms_hi.dwd.tab.dwd_tab_end_piece_base_hi import jms_dwd__dwd_tab_end_piece_base_hi
from jms_hi.dwd.tab.dwd_yl_oms_interceptorpiece_base_hi import jms_dwd__dwd_yl_oms_interceptorpiece_base_hi
from jms_hi.dwd.dwd_dependent_hi.dwd_dependent_hi_dwd_wide_yl_rt_ssmx_bill_detail_hf import jms_dwd__dwd_dependent_hi_dwd_wide_yl_rt_ssmx_bill_detail_hf
jms_dm__dm_interceptor_warning_detail_hi = SparkSqlOperator(
    task_id='jms_dm__dm_interceptor_warning_detail_hi',
    task_concurrency=1,
    pool_slots=3,
    master='yarn',
    execution_timeout=timedelta(hours=1),
    depends_on_past=True,
    email=['wangmenglei@jtexpress.com','yl_bigdata@yl-scm.com'],
    name='jms_dm__dm_interceptor_warning_detail_hi_{{ execution_date | cst_hour }}',
    sql='jms_hi/dm/dm_interceptor_warning_detail_hi/execute.sql',
    driver_memory='4G' ,
    driver_cores=4 ,
    executor_cores=5,
    executor_memory='12G',
    num_executors=10,
    retries=0,
    conf={
        'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
        'spark.shuffle.service.enabled': 'true',  # 动态资源 Shuffle 服务开启
        'spark.dynamicAllocation.maxExecutors'             : 30 ,
        'spark.dynamicAllocation.cachedExecutorIdleTimeout': 120,  # 动态资源自动释放闲置 Executor 的超时时间(s)
        'spark.dynamicAllocation.executorIdleTimeout':'120s',
        'spark.locality.wait.node':'100ms',
        'spark.executor.memoryOverhead'             : '4G' ,
        'spark.hadoop.hive.exec.dynamic.partition.mode': 'nonstrict', # 动态分区
        'spark.hadoop.hive.exec.dynamic.partition': 'true',
        'spark.sql.shuffle.partitions': 450,
        'spark.shuffle.file.buffer':'64k',
        'spark.shuffle.consolidateFiles': 'true',
        'spark.shuffle.memoryFraction': '0.8',
        'spark.executor.extraJavaOptions': '-XX:+UseG1GC -XX:ParallelGCThreads=5 -XX:ConcGCThreads=2'
    },
    hiveconf={'hive.exec.dynamic.partition': 'true',
              'hive.exec.dynamic.partition.mode': 'nonstrict',
              'hive.exec.max.dynamic.partitions.pernode': 200,
              'hive.exec.max.dynamic.partitions': 200
              },
    yarn_queue='pro',
)

jms_dm__dm_interceptor_warning_detail_hi  << [
    jms_dim__dim_network_whole_massage,
    jms_dwd__dwd_tab_barscan_arrival_base_hi,
    jms_dwd__dwd_tab_barscan_send_base_hi,
    jms_dwd__dwd_wide_tms_road_waybill_hf,
    jms_dwd__dwd_tab_reback_transfer_express_base_hi,
    jms_dwd__dwd_tab_end_piece_base_hi,
    jms_dwd__dwd_yl_oms_interceptorpiece_base_hi,
    jms_dwd__dwd_dependent_hi_dwd_wide_yl_rt_ssmx_bill_detail_hf,
]
 